//package cn.sdormitory.controller;
//
//import cn.sdormitory.basedata.entity.BClass;
//import cn.sdormitory.basedata.entity.BStudent;
//import cn.sdormitory.common.constant.CommonConstant;
//import cn.sdormitory.common.dto.ResultMsg;
//import cn.sdormitory.service.AppDictDetailService;
//import cn.sdormitory.service.AppLeaveService;
//import cn.sdormitory.service.AppStudentService;
//import cn.sdormitory.service.AppUserService;
//import cn.sdormitory.smartdor.entity.SdLeave;
//import cn.sdormitory.sys.entity.SysDictDetail;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.*;
//
//import java.util.List;
//import java.util.Objects;
//
///**
// * @创建人：zhouyang
// * @创建时间：2020/12/28 17:07
// * @version：V1.0
// */
//@RestController
//@RequestMapping("/app/Leave")
//@Api("APP端请假管理接口")
//public class AppLeaveController {
//    @Autowired
//    private AppStudentService appStudentService;
//    @Autowired
//    private AppLeaveService appLeaveService;
//    @Autowired
//    private AppDictDetailService appDictDetailService;
//    @Autowired
//    private AppUserService appUserService;
//
//    @ApiOperation(value = "请假列表")
//    @GetMapping("/getLeaveByAccId")
//    public ResultMsg getLeaveByAccId(int accountId, String tokenPrefix,String leaveDate) {
//        if(!"".equals(tokenPrefix) && tokenPrefix != null){
//            if(tokenPrefix.equals(CommonConstant.TOKEN_USER)){
//                List<SdLeave> leaveList=appLeaveService.getLeaveAll(leaveDate);
//                return  ResultMsg.BY_SUCCESS("获取成功",leaveList);
//            }else{
//                BStudent bStudent=appStudentService.getStudentById(accountId);
//                List<SdLeave> leaveList=appLeaveService.getLeaveByStuNo(bStudent.getStudentNo(),leaveDate);
//                return  ResultMsg.BY_SUCCESS("获取成功",leaveList);
//            }
//        }else{
//            return  ResultMsg.BY_ERROR("token不能为空!!!");
//        }
//    }
//
//    //根据请假ID获取请假详情
//    @ApiOperation(value = "请假详情")
//    @GetMapping("/getLeaveById")
//    public ResultMsg getLeaveById(Long id){
//        SdLeave sdLeave = appLeaveService.getLeaveById(id);
//        if(sdLeave != null){
//            return ResultMsg.BY_SUCCESS("查询请假详情成功", sdLeave);
//        }else{
//            return ResultMsg.BY_FAIL("查询请假详情失败");
//        }
//    }
//
//    //获取请假类型列表
//    @ApiOperation(value = "请假类型列表")
//    @GetMapping("/getleaveType")
//    public ResultMsg getleaveType(String dictType){
//        List<SysDictDetail> sysDictDetails = appDictDetailService.selectDictDataByType(dictType);
//        if(sysDictDetails != null && sysDictDetails.size()>0){
//            return ResultMsg.BY_SUCCESS("查询请假类型列表成功", sysDictDetails);
//        }else{
//            return ResultMsg.BY_FAIL("查询请假详情失败");
//        }
//    }
//
//    //学员新增请假申请
//    @ApiOperation(value = "请假申请")
//    @PostMapping("/saveLeave")
//    public ResultMsg saveLeave(@RequestBody SdLeave sdLeave){
//        //每个学员每天应只有一条请假记录
//        SdLeave sdLeave1=appLeaveService.getLeaveByStuNoAndLeaDate(sdLeave.getStudentNo(),sdLeave.getLeaveDate());
//        if (sdLeave1 != null) {
//            return ResultMsg.BY_ERROR("该学员当天请假数据已录入!!!",-3);
//        }
//        int result = appLeaveService.saveLeave(sdLeave);
//        if(result>0){
//            return ResultMsg.BY_SUCCESS("申请请假成功!!!");
//        }else{
//            return ResultMsg.BY_FAIL("申请请假失败!!!");
//        }
//    }
//
//    //修改请假申请
//    @ApiOperation(value = "修改请假申请")
//    @PostMapping("/modifyLeave")
//    public ResultMsg modifyLeave(@RequestBody SdLeave sdLeave){
//        //每个学员每天应只有一条请假记录
//        SdLeave leave=appLeaveService.getLeaveById(sdLeave.getId());
//        SdLeave sdLeave1=appLeaveService.getLeaveByStuNoAndLeaDate(leave.getStudentNo(),sdLeave.getLeaveDate());
//        if (sdLeave1 != null && !Objects.equals(sdLeave1.getId(),sdLeave.getId())) {
//            return ResultMsg.BY_ERROR("该学员当天请假数据已录入!!!",-3);
//        }
//        int result = appLeaveService.modifyLeave(sdLeave);
//        if(result>0){
//            return ResultMsg.BY_SUCCESS("修改成功!!!",result);
//        }else{
//            return ResultMsg.BY_FAIL("修改失败!!!");
//        }
//    }
//
//    //请假审核
//    @ApiOperation(value = "请假审核")
//    @PostMapping("/parentAudit")
//    public ResultMsg parentAudit(@RequestBody SdLeave sdLeave){
//        if(appLeaveService.auditLeave(sdLeave)>0){
//            return ResultMsg.BY_SUCCESS("审核成功!!!");
//        }else{
//            return ResultMsg.BY_FAIL("审核失败，请联系管理员!!!");
//        }
//    }
//
//    @ApiOperation("getRoleTeaCount => APP端获取当前用户是否拥有班主任角色")
//    @GetMapping("/getRoleTeaCount")
//    public int getRoleTeaCount(int id){
//        int roleCount=appUserService.getRoleTeaCount(id);
//        return roleCount;
//    }
//
//    @ApiOperation("getClassByTeaId => APP端根据班主任ID查询对应班级列表信息")
//    @GetMapping(value = "/getClassByTeaId")
//    public ResultMsg getClassByTeaId(Long teacherId)  {
//        List<BClass> bClassList=appLeaveService.getClassByTeaId(teacherId);
//        return ResultMsg.BY_SUCCESS("获取成功",bClassList);
//    }
//
//    //班主任新增快捷请假申请
//    @ApiOperation(value = "快捷请假申请")
//    @PostMapping("/saveLeaveTea")
//    public ResultMsg saveLeaveTea(@RequestBody SdLeave sdLeave){
//        //判断学号是否存在
//        BStudent bStudent=appStudentService.getByStudentNo(sdLeave.getStudentNo());
//        if("".equals(bStudent) || bStudent==null){
//            return ResultMsg.BY_ERROR("此学号不存在!!!",-1);
//        }
//        //判断学号+学生姓名+班级是否匹配
//        BStudent student=appStudentService.getByStuNoAndNameAndClassId(sdLeave.getStudentNo(),sdLeave.getStudentName(),sdLeave.getClassId());
//        if(student==null){
//            return ResultMsg.BY_ERROR("输入的学号、班级、姓名不匹配!!!",-2);
//        }
//        if(!"".equals(bStudent) && bStudent!=null) {
//            //每个学员每天应只有一条请假记录
//            SdLeave sdLeave1=appLeaveService.getLeaveByStuNoAndLeaDate(sdLeave.getStudentNo(),sdLeave.getLeaveDate());
//            if (sdLeave1 != null) {
//                return ResultMsg.BY_ERROR("该学员当天请假数据已录入!!!",-3);
//            }
//        }
//        int result = appLeaveService.saveLeaveTea(sdLeave);
//        if(result>0){
//            return ResultMsg.BY_SUCCESS("快捷请假申请成功!!!",result);
//        }else{
//            return ResultMsg.BY_FAIL("快捷请假申请失败!!!");
//        }
//    }
//}
